﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace AdvanceLib.UI
{
    public class RenderEngine
    {
        #region Fields
        private Graphics _graphics;
        #endregion

        #region Properties
        public Graphics Graphics
        {
            get { return _graphics; }
            set { _graphics = value; }
        }
        #endregion

        #region Methods
        public GraphicsPath CreateBorderRadius(Rectangle rect, int radius)
        {
            GraphicsPath path = new GraphicsPath();

            path.AddLine(rect.X + radius, rect.Y, rect.X + rect.Width - radius, rect.Y);
            path.AddArc(rect.X + rect.Width - radius, rect.Y, radius, radius, 270, 90);

            path.AddLine(rect.X + rect.Width, rect.Y + radius, rect.X + rect.Width, rect.Y + rect.Height - radius);
            path.AddArc(rect.X + rect.Width - radius, rect.Y + rect.Height - radius, radius, radius, 0, 90);

            path.AddLine(rect.X + rect.Width - radius, rect.Y + rect.Height, rect.X + radius, rect.Y + rect.Height);
            path.AddArc(rect.X, rect.Y + rect.Height - radius, radius, radius, 90, 90);

            path.AddLine(rect.X, rect.Y + rect.Height - radius, rect.X, rect.Y + radius);
            path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);

            path.CloseFigure();

            return path;
        }
        public void RenderBorderRadius(Brush brush, Rectangle rect, int radius)
        {
            GraphicsPath path = CreateBorderRadius(rect, radius);
            Graphics.FillPath(brush, path);
        }
        public void RenderBorderRadius(Pen pen, Rectangle rect, int radius)
        {
            GraphicsPath path = CreateBorderRadius(rect, radius);
            Graphics.DrawPath(pen, path);
        }
        public Color Lerp(Color color1, Color color2, float opacity)
        {
            int partR = (int)((color2.R - color1.R) * opacity);
            int partG = (int)((color2.G - color1.G) * opacity);
            int partB = (int)((color2.B - color1.B) * opacity);

            return Color.FromArgb(255, color1.R + partR, color1.G + partG, color1.B + partB);
        }
        #endregion
    }
}
